package com.hd.usercenter.controller;

import com.hd.usercenter.model.domain.Request.UserRegisterRequest;
import com.hd.usercenter.service.impl.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/register")
    public long userRegister(@RequestBody UserRegisterRequest userRegisterRequest){
        if(userRegisterRequest == null){
            return Long.parseLong(null);
        }
        String userAccount = userRegisterRequest.getUserAccout();
        String userPassword = userRegisterRequest.getUserPassword();
        String checkPassword = userRegisterRequest.getCheckPassword();

        return userService.userRegister(userAccount,userPassword,checkPassword);
    }

    @PostMapping("/login")
    public long userLogin(@RequestBody UserRegisterRequest userRegisterRequest, HttpServletRequest request){
        if(userRegisterRequest == null){
            return Long.parseLong(null);
        }
        String userAccount = userRegisterRequest.getUserAccout();
        String userPassword = userRegisterRequest.getUserPassword();
        String checkPassword = userRegisterRequest.getCheckPassword();
        return userService.userLogin(userAccount,userPassword,request);

    }
}
